/*
 * pthread.cpp
 *
 *  Created on: 2012-6-26
 *      Author: lucid
 */

#include "semaphore_f.h"


semaphoref_t::semaphoref_t()
{
	sem_init(&m_sem,0,0);
}

semaphoref_t::~semaphoref_t()
{
	sem_destroy(&m_sem);
}

void semaphoref_t::post()
{
	sem_post(&m_sem);
}

void semaphoref_t::clear()
{
	int iVal;
	do
	{
		sem_trywait(&m_sem);
		sem_getvalue(&m_sem,&iVal);
	}while(iVal);
}

int semaphoref_t::wait()
{
	return sem_wait(&m_sem);
}

void semaphoref_t::SemSetValue()
{

}
